using System.Collections;
using UnityEngine;

public class Singleton<T> :MonoBehaviour
    where T : MonoBehaviour
{
    private static T _instance;

    public static T instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = FindObjectOfType<T>();

                if (instance == null)
                {
                    Debug.LogError("Cannot find " + typeof(T) + "!");
                }
            }

            return _instance;
        }
    }

}